home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_363 / bootbase / src / bootbase.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  37KB  |  1,248 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <exec/devices.h>
  4. #include <exec/execbase.h>
  5. #include <intuition/intuition.h>
  6. #include <intuition/intuitionbase.h>
  7. #include <devices/trackdisk.h>
  8. #include <libraries/dos.h>
  9. #include <libraries/dosextens.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include "BootBase.h"
  13. #include "rawkey.h"
  14.  
  15. char IDstring[47] = {"BootBase V2.3 - Steven Lagerweij 5-apr-90"};
  16.  
  17. #define  BIG    1500L
  18. #define  READ   1005L
  19. #define  WRITE  1006L
  20. #define  BUFFER    1024
  21. #define  NUMHEADS  2
  22. #define  PROTECT   "Disk is write-protected "
  23. #define  NODISK    "No disk present.        "
  24. #define  NOMEM     "Not enough memory.      "
  25. #define  NOEXT     "Can't CreateExtIo().    "
  26. #define  NOPORT    "Can't CreatePort().     "
  27. #define  NOPROB    "No failures.            "
  28. #define  NODEV     "Drive is occupied!      "
  29. #define  EMPTY     "                        "
  30. #define  CANCELED  10
  31. #define  TOSHORT   20
  32. #define  NOMATCH   30
  33. #define  MATCH     40
  34. #define  EXTSTAND  50
  35. #define  NOINFO    60
  36. #define  NOWIN     70
  37.  
  38. char seldr[8] = {" DFx "};                          /* active gadget text*/
  39.  
  40.  
  41. extern struct ExecBase      *SysBase;        /* Libraries */
  42. extern struct DosLibrary    *DOSBase;
  43.        struct IntuitionBase *IntuitionBase;
  44.        struct GfxBase       *GfxBase;
  45.  
  46.        struct Window        *OpenWindow();
  47. void                        *OpenLibrary();
  48. extern struct MsgPort       *CreatePort();
  49. extern struct IORequest     *CreateExtIO();
  50.        struct Message       *GetMsg();
  51.  
  52.        struct MsgPort       *diskport;
  53.        struct IOExtTD       *diskreq;
  54.        struct Screen        *screen;
  55.        struct Window        *FirstWindow,*wlist,*reqwin;
  56.        struct IntuiMessage  *message;
  57.        struct Gadget        *GadgetPtr;
  58.        struct IntuiText      DriveText =
  59.                                 { 2,3,JAM2, 0,0, NULL, &seldr[0], NULL };
  60.  
  61.  
  62. ULONG  MessageClass;
  63. USHORT code, GadgetID;
  64. BYTE  *diskbuffer,Map[BUFFER];      /* Buffer for bootblock and file */
  65. ULONG  diskchangecount,remcount[4]; /* Diskchangecounters to see which drive changed disk*/
  66. long   drive = 0,availdrives[4];      /* Current drive and available drives */
  67.  
  68.  
  69. char *ReqTexts[20] = {   /* Requester texts */
  70. "You are about to rewrite  ",
  71. "this disk's bootblock     ",
  72. "Are you sure you want this ?",
  73. "Do you wish to quit ?",
  74. "There are windows/programs",
  75. "which are NOT opened by me",
  76. "Do you wish to QUIT or",
  77. "REMOVE them first",
  78. "Select YES to quit",
  79. "NO to cancel",
  80. };
  81.  
  82. BYTE standard[55] = {  /* Code for standard bootblock */
  83. 0x44,0x4f,0x53,0x00,0xc0,0x20,0x0f,0x19,0x00,0x00,0x03,0x70,
  84. 0x43,0xfa,0x00,0x18,0x4e,0xae,0xff,0xa0,0x4a,0x80,0x67,0x0a,
  85. 0x20,0x40,0x20,0x68,0x00,0x16,0x70,0x00,0x4e,0x75,0x70,0xff,
  86. 0x60,0xfa,0x64,0x6f,0x73,0x2e,0x6c,0x69,0x62,0x72,0x61,0x72,
  87. 0x79
  88. }; /* the rest is filled with zeros */
  89.  
  90. char file[64];                                      /* Filereq */
  91. char readdir[64] = {"BBS:"};                        /* Filereq */
  92. char writedir[64] = {"BBS:"};                       /* FileReq */
  93. char currcomment[81], Attached[128], tmp[100];      /* Comment, Filepath, temp store */
  94. char kindofbb[100] = {"                         "}; /* BB Name */
  95. char *Readptr,*Writeptr;                            /* Pointers for file operation */
  96. char CompPath[5] = {"BBS:"};                        /* Logical assignment/path */
  97. char *LeftMouse = (char *) 0xBFE001;                /* To test leftbutton directly, without intuitionmessage */
  98.  
  99. short comflag     = FALSE; /* Comment on ? */
  100. short AutoCompare = FALSE; /* Flag for autocompare function */
  101. short AutoRead    = FALSE; /* Flag for autoread bb from inserted disk */
  102. short setupcnt    = TRUE;  /* Little flag to get diskchangecounts at startup */
  103. short PAL         = TRUE;  /* PAL machine ? (see main()) */
  104. short VisualComp  = FALSE;  /* If this flag is set the graphics will be printed */
  105. short isthereabb  = FALSE; /* Is there a bootblock in buffer? - flag */
  106.  
  107. VOID _main()
  108. {
  109.    if(SysBase->VBlankFrequency != 0x32) PAL = FALSE;
  110.  
  111.    /* Find available drives */
  112.    GadgetPtr = &StringGadget;
  113.    if(FindUnit("DF0:"))
  114.     { GadgetPtr->NextGadget = &df0gag; GadgetPtr = &df0gag; availdrives[0] = TRUE; }
  115.    else availdrives[0] = FALSE;
  116.    if(FindUnit("DF1:"))
  117.     { GadgetPtr->NextGadget = &df1gag; GadgetPtr = &df1gag; availdrives[1] = TRUE; }
  118.    else availdrives[1] = FALSE;
  119.    if(FindUnit("DF2:"))
  120.     { GadgetPtr->NextGadget = &df2gag; GadgetPtr = &df2gag; availdrives[2] = TRUE; }
  121.    else availdrives[2] = FALSE;
  122.    if(FindUnit("DF3:"))
  123.     { GadgetPtr->NextGadget = &df3gag; availdrives[3] = TRUE; }
  124.    else availdrives[3] = FALSE;
  125.    if(!PAL)
  126.      {
  127.         FirstNewWindow.Height = 200;
  128.         ns.Height             = 200;
  129.      }
  130.    Open_All();  /* Windows screen etc opened in here */
  131.  
  132.    DiskIns(); setupcnt = FALSE; /* Get change counts */
  133.    drive = 1; GadgetID = 14; DriveSelect(); /* DF0 Active */
  134.  
  135.    LayOut(); /* Build screen outlay*/
  136.    for(;;)
  137.      {
  138.       if ((message = (struct IntuiMessage *)
  139.           GetMsg(FirstWindow->UserPort)) == NULL)
  140.             {
  141.                 Wait(1<<FirstWindow->UserPort->mp_SigBit);
  142.                 continue;
  143.             }
  144.       MessageClass = message->Class;
  145.       code      = message->Code;
  146.       GadgetPtr = (struct Gadget *) message->IAddress;
  147.       GadgetID  = GadgetPtr->GadgetID;
  148.       ReplyMsg(message);
  149.  
  150.  
  151.       switch (MessageClass)
  152.          {
  153.          case MOUSEBUTTONS: if(code == MENUDOWN)
  154.                                Help(FirstWindow->MouseX,FirstWindow->MouseY);
  155.                             break;
  156.          case RAWKEY        : Do_RawKey(code);
  157.                               break;
  158.          case GADGETUP      : GadgetActs();
  159.                               break;
  160.          case DISKINSERTED  :
  161.                               if(DiskIns() == 0)
  162.                                 {
  163.                                   if(AutoRead) ErrPrint(ShowBootBlock());
  164.                                 }
  165.                               break;
  166.  
  167.          }
  168.      }
  169. }
  170.  
  171.  
  172. Open_All()
  173. {
  174.  
  175.    if((diskbuffer = (BYTE *)
  176.        AllocMem(BUFFER,MEMF_CHIP)) == NULL)
  177.       {
  178.       printf("Couldn't not allocate chip-memory for diskbuffer\n");
  179.       exit(FALSE);
  180.       }
  181.    if (!(IntuitionBase = (struct IntuitionBase *)
  182.          OpenLibrary("intuition.library", 0L)))
  183.       {
  184.       printf("Intuition Library failure!\n");
  185.       Close_All();
  186.       }
  187.    if((GfxBase = (struct GfxBase *)
  188.                     OpenLibrary("graphics.library",0)) == NULL)
  189.       {
  190.       printf("Can't open Graphics library!\n");
  191.       Close_All();
  192.       }
  193.    if(!(screen=(struct Screen *)OpenScreen(&ns)))
  194.    {
  195.       printf("Can't open screen!\n");
  196.       Close_All();
  197.    }
  198.    FirstNewWindow.Screen=screen;
  199.    ReqWindow.Screen     =screen;
  200.  
  201.    if (!(FirstWindow = (struct Window *)OpenWindow(&FirstNewWindow)))
  202.       {
  203.       printf("Can't open Window!\n");
  204.       Close_All();
  205.       }
  206.    return(0);
  207. }
  208.  
  209. Close_All()   /* Everything that is opened will be closed */
  210. {
  211. short morewins = FALSE;
  212. CLD();
  213.  
  214. if(screen)
  215.   {
  216.     for(wlist = screen->FirstWindow;wlist != NULL;wlist = wlist->NextWindow)
  217.       {
  218.         if(wlist != FirstWindow)
  219.           {
  220.             morewins++;
  221.             Locate(4+morewins,2);
  222.             sprintf(&tmp[0],"Error first remove window/program: %s",
  223.                                                     (UBYTE *)wlist->Title);
  224.             Print(&tmp[0]);
  225.           }
  226.       }
  227.   }
  228.    if((morewins) && (!AreYouSure(4,6,3))) return(FALSE);
  229.    if(diskbuffer)       FreeMem(diskbuffer,BUFFER);
  230.    if (FirstWindow)     CloseWindow(FirstWindow);
  231.    if (GfxBase)         CloseLibrary(GfxBase);
  232.    if (IntuitionBase)   CloseLibrary(IntuitionBase);
  233.    if (screen)          CloseScreen(screen);
  234.    exit(0);
  235. }
  236.  
  237.  
  238. Locate(y,x)  /* To locate the cursor for text printing */
  239. short  y,x;
  240. {
  241.     short rx,ry;    /* Real x and y */
  242.     rx=x*8;
  243.     ry=y*8;
  244.     ry=ry+16;
  245.     if(ry<24)  ry=24;
  246.     if(ry>248) ry=248;
  247.     if(rx<1)   rx=1;
  248.     if(rx>632) rx=632;
  249.  
  250.     if((!PAL) && (ry > 200)) ry = 200;
  251.     Move(FirstWindow->RPort,rx,ry);
  252.     return(0);
  253. }
  254.  
  255. Print(line)   /* Print a string */
  256. char line[100];
  257. {
  258.     Text(FirstWindow->RPort,&line[0],strlen(&line[0]));
  259.     return(0);
  260. }
  261.  
  262. ErrPrint(line)  /* Print string at specific position - errors fe. */
  263. char *line;
  264. {
  265.     SetColor(1,0); Locate(3,12);
  266.     Print("                                                 ");
  267.     Locate(3,12); Print(&line[0]);
  268.     return(0);
  269. }
  270.  
  271. SetColor(f,b)
  272. short    f,b;   /* Voor en achtergrondkleur */
  273. {
  274.     if(f<0 || f>3) f=1;
  275.     if(b<0 || b>3) b=0;
  276.     SetAPen(FirstWindow->RPort,f);
  277.     SetBPen(FirstWindow->RPort,b);
  278.     return(0);
  279. }
  280.  
  281. ReadCylSec(cyl,sec,hd) /* Read 1024(BUFFER) bytes from disk */
  282. SHORT cyl,sec,hd;
  283. {
  284.    LONG offset;
  285.  
  286.    diskreq->iotd_Req.io_Length = BUFFER;
  287.    diskreq->iotd_Req.io_Data   = (APTR)diskbuffer;
  288.    diskreq->iotd_Req.io_Command = ETD_READ;
  289.    diskreq->iotd_Count = diskchangecount;
  290.    offset = TD_SECTOR * (sec + NUMSECS * hd + NUMSECS * NUMHEADS * cyl);
  291.    diskreq->iotd_Req.io_Offset = offset;
  292.    DoIO(diskreq);
  293. return(0);
  294. }
  295.  
  296. MotorOn()  /* Drive motor on */
  297. {
  298.    diskreq->iotd_Req.io_Length  = 1;
  299.    diskreq->iotd_Req.io_Command = TD_MOTOR;
  300.    DoIO(diskreq);
  301. return(0);
  302. }
  303.  
  304. MotorOff()  /* Drive motor off */
  305. {
  306.    diskreq->iotd_Req.io_Length  = 0;
  307.    diskreq->iotd_Req.io_Command = TD_MOTOR;
  308.    DoIO(diskreq);
  309. return(0);
  310. }
  311.  
  312. struct IORequest *CreateExtIO(ioReplyPort,size) /* create extended I/O */
  313.       struct MsgPort *ioReplyPort;
  314.       LONG size;
  315. {
  316.       struct IORequest *ioReq;
  317.  
  318.    if(ioReplyPort == 0)
  319.       return((struct IORequest *) 0);
  320.  
  321.    ioReq = (struct IORequest *)AllocMem (size,MEMF_CLEAR | MEMF_PUBLIC);
  322.    if(ioReq==0)
  323.       return((struct IORequest *) 0);
  324.    ioReq->io_Message.mn_Node.ln_Type = NT_MESSAGE;
  325.    ioReq->io_Message.mn_Node.ln_Pri = 0;
  326.    ioReq->io_Message.mn_ReplyPort = ioReplyPort;
  327.    return(ioReq);
  328. }
  329.  
  330. DeleteExtIO(ioExt,size) /* Remove Extendend I/O */
  331.    struct IORequest *ioExt;
  332.    LONG size;
  333. {
  334.    ioExt->io_Message.mn_Node.ln_Type = 0xff;
  335.    ioExt->io_Device = (struct Device *) -1;
  336.    ioExt->io_Unit = (struct Unit *) -1;
  337.    FreeMem(ioExt,size);
  338. return(0);
  339. }
  340.  
  341.  
  342. ShowBootBlock()   /* Read bootblock from disk and show it on screen */
  343. {
  344. short readerr,tst;
  345. char oneline[100];
  346.  
  347.    if((diskport = CreatePort(0,0)) == 0)
  348.      { return(NOPORT); };
  349.  
  350.    if((diskreq = (struct IOExtTD *)
  351.              CreateExtIO(diskport,sizeof(struct IOExtTD))) == NULL)
  352.      { DeletePort(diskport); return(NOEXT);};
  353.  
  354.    if(OpenDevice(TD_NAME,drive,diskreq,0))
  355.      {
  356.        DeleteExtIO(diskreq,sizeof(struct IOExtID));
  357.        DeletePort(diskport);
  358.        return(NODEV);
  359.      }
  360.    diskreq->iotd_Req.io_Command = TD_CHANGESTATE;
  361.    DoIO(diskreq);
  362.    if(diskreq->iotd_Req.io_Actual != 0)
  363.     {
  364.        CloseDevice(diskreq);
  365.        DeleteExtIO(diskreq,sizeof(struct IOExtTD));
  366.        DeletePort(diskport);
  367.        return(NODISK);
  368.     }
  369.    diskreq->iotd_Req.io_Command = TD_CHANGENUM;
  370.    DoIO(diskreq);
  371.    diskchangecount = diskreq->iotd_Req.io_Actual;
  372.    remcount[drive] = diskchangecount;
  373.    MotorOn();
  374.    ReadCylSec(0,0,0);
  375.    readerr=diskreq->iotd_Req.io_Error;
  376.    MotorOff();
  377.    if(readerr != 0)
  378.       {
  379.         CLD();
  380.         sprintf(&oneline[0],"Read Error: %d",readerr);
  381.         SetColor(3,0);
  382.         if(isthereabb) PrintCurrentBB();
  383.         return(&oneline[0]);
  384.       }
  385.    else
  386.       {
  387.         CLD();
  388.         tst = CheckIfStandard();
  389.  
  390.         if(tst == 1)      sprintf(&kindofbb[0],"Standard 1.2/1.3         ");
  391.         else if(tst == 2) sprintf(&kindofbb[0],"Do nothing bootblock     ");
  392.         else              sprintf(&kindofbb[0],"Not identified !         ");
  393.         isthereabb = TRUE;
  394.         SetColor(1,0);
  395.         PrintCurrentBB();
  396.         if((AutoCompare) && (!tst)) DoComparing();
  397.         else            Grafiek(1);
  398.         StringBuffer[0] = '\0'; UndoBuffer[0] = '\0';
  399.         RefreshGadgets(&StringGadget,FirstWindow,NULL);
  400.       }
  401.    CloseDevice(diskreq);
  402.    DeleteExtIO(diskreq,sizeof(struct IOExtTD));
  403.    DeletePort(diskport);
  404. LayOut();
  405. return(NOPROB);
  406. }
  407.  
  408. CLD()
  409. {
  410.     SetColor(0,0);
  411.     RectFill(FirstWindow->RPort,12,47,528,178);
  412.     SetColor(1,0);
  413. return(0);
  414. }
  415.  
  416. PrintCurrentBB()
  417. {
  418. char oneline[100];
  419. short ypos = 5,xpos;
  420. short bufpos = 0;
  421. int kar;
  422.         for(bufpos=0;bufpos<1024;bufpos+=64)
  423.           {
  424.             for(xpos=0;xpos<64;xpos++)
  425.               {
  426.                 kar = diskbuffer[(bufpos+xpos)];
  427.                 if((kar > 31) && (kar < 217)) oneline[xpos] = kar;
  428.                 else                          oneline[xpos] = '.';
  429.               }
  430.             oneline[64] = '\0';
  431.             Locate(ypos,2); Print(&oneline[0]);
  432.             ypos++;
  433.           }
  434. return(0);
  435. }
  436.  
  437. LayOut()
  438. {
  439.     SetColor(2,0);
  440.     DrawBox(10,45,530,180); /* Box around bootblock */
  441.     DrawBox(11,46,529,179);
  442.  
  443.     DrawBox(10,13,530,45);  /* Box around error messages */
  444.     DrawBox(11,14,529,44);
  445.  
  446.     DrawBox(541,17,639,43); /* Box around read/write boot gags */
  447.     DrawBox(542,17,640,43); /* Box around read/write boot gags */
  448.  
  449.     DrawBox(541,43,639,72); /* Box around read/write file gadgets */
  450.     DrawBox(542,43,640,72); /* Box around read/write file gadgets */
  451.  
  452.     SetColor(3,0);
  453.     Locate(1,2); Print("Name    :                                         ");
  454.     Locate(2,2); Print("Comment : ");
  455.     Locate(3,2); Print("Error   : ");
  456.     SetColor(1,0);
  457.     Locate(1,12); Print(&kindofbb[0]);
  458.  
  459.     Move(FirstWindow->RPort,548,25); Print(" Bootblock");
  460.     Move(FirstWindow->RPort,548,55); Print("   File   ");
  461.     if(isthereabb) PrintCurrentBB();
  462.     else {
  463.         CLD();
  464.         Locate(5,2); Print("BootBase v2.3 - by Steven Lagerweij");
  465.         Locate(6,2); Print("Click with left button to perform the function");
  466.         Locate(7,2); Print("Click with right button to see help about a function");
  467.         Locate(8,2); Print("Press HELP to see the keys");
  468.     }
  469. return(0);
  470. }
  471.  
  472. FindUnit(devname)
  473. char devname[50];
  474. {
  475. struct   DeviceList    *zoekdev;
  476. char isithim[50];
  477. zoekdev = (struct DeviceList *) BADDR(((struct DosInfo *)
  478.        BADDR(((struct RootNode *) (DOSBase->dl_Root))->rn_Info))->di_DevInfo);
  479.  
  480. while(zoekdev != 0)
  481.     {
  482.         sprintf(&isithim[0],"%s:",BADDR(zoekdev->dl_Name)+1);
  483.         if((zoekdev->dl_Type == DLT_DEVICE) &&
  484.            (stcpma(&devname[0],&isithim[0])))
  485.             return(TRUE);
  486.         zoekdev = (struct DeviceList *)BADDR(zoekdev->dl_Next);
  487.     }
  488. return(FALSE);
  489. }
  490.  
  491.  
  492. GadgetActs()
  493. {
  494.  
  495.       switch(GadgetID)
  496.         {
  497. /* Read BB  */     case 1 :  ErrPrint(ShowBootBlock()); break;
  498.  
  499. /* Write BB */     case 2 :  if(AreYouSure(0,3,3)) WriteBootBlock(); break;
  500.  
  501. /*Read from file*/ case 3 :  ReadFile(); break;
  502. /*Write to file*/  case 4 :  WriteToFile(); break;
  503. /*Toggle compare*/ case 5 :  if(AutoCompare) AutoCompare = FALSE;
  504.                              else            AutoCompare = TRUE;
  505.                              break;
  506. /*Toggle diskins*/ case 6 :  if(AutoRead) AutoRead = FALSE;
  507. /*Auto read disk*/           else         AutoRead = TRUE;
  508.                              break;
  509. /* Quit */         case 7 :  if(AreYouSure(3,1,3)) Close_All(); break;
  510. /* Noboot bb */    case 8 :  MakeNobootbuf(); Grafiek(1); break;
  511. /* Standard bb*/   case 9 :  MakeStanbuf(); Grafiek(1); break;
  512. /*Toggle comments*/case 10:  if(comflag) comflag = FALSE;
  513.                              else        comflag = TRUE;
  514.                              break;
  515. /*DF0*/            case 14:
  516. /*DF1*/            case 13:
  517. /*DF2*/            case 12:
  518. /*DF3*/            case 11:  DriveSelect(); break;
  519.         }
  520. return(0);
  521. }
  522.  
  523.  
  524. DriveSelect()
  525. {
  526.   long td;
  527.  
  528.  
  529.     td = (GadgetID - 14) * -1;
  530.     if((td < 0) || (!availdrives[td])) return(0);
  531.     if(td == drive) return(0);
  532.  
  533.     drive = td; seldr[3] = '0'+drive;
  534.  
  535.     df0gag.GadgetText = &DF0Text; df1gag.GadgetText = &DF1Text;
  536.     df2gag.GadgetText = &DF2Text; df3gag.GadgetText = &DF3Text;
  537.     df0gag.GadgetRender = (APTR)&OffBorder;
  538.     df1gag.GadgetRender = (APTR)&OffBorder;
  539.     df2gag.GadgetRender = (APTR)&OffBorder;
  540.     df3gag.GadgetRender = (APTR)&OffBorder;
  541.  
  542.     switch(drive)
  543.       {
  544.         case 0: df0gag.GadgetText = &DriveText;
  545.                 df0gag.GadgetRender = (APTR)&OnBorder; break;
  546.  
  547.         case 1: df1gag.GadgetText = &DriveText;
  548.                 df1gag.GadgetRender =  (APTR)&OnBorder; break;
  549.  
  550.         case 2: df2gag.GadgetText = &DriveText;
  551.                 df2gag.GadgetRender = (APTR)&OnBorder; break;
  552.  
  553.         case 3: df3gag.GadgetText = &DriveText;
  554.                 df3gag.GadgetRender = (APTR)&OnBorder; break;
  555.       }
  556.     SetColor(0,0); RectFill(FirstWindow->RPort,543,75,639,96);
  557.     RefreshGadgets(&StringGadget,FirstWindow,NULL);
  558. return(0);
  559. }
  560.  
  561.  
  562.  
  563. DrawBox(x1,y1,x2,y2)
  564. short x1,y1,x2,y2;
  565. {
  566.     Move(FirstWindow->RPort,x1,y1);
  567.     Draw(FirstWindow->RPort,x2,y1);
  568.     Draw(FirstWindow->RPort,x2,y2);
  569.     Draw(FirstWindow->RPort,x1,y2);
  570.     Draw(FirstWindow->RPort,x1,y1);
  571. return(0);
  572. }
  573.  
  574. WriteToFile()
  575. {
  576.    long ret;
  577.  
  578.    file[0] = '\0';
  579.  
  580.    if(!isthereabb)
  581.      { ErrPrint("No bootblock available!"); return(FALSE); };
  582.  
  583.    ret = arpreq("Write bootblock to file", file, writedir, FirstWindow);
  584.     if((ret != 0) && (file[0] != '\0'))
  585.       {
  586.         Koppel(&writedir[0],&file[0]);
  587.         if((Writeptr = (char *)Open(&Attached[0],WRITE)) == 0L) goto quit;
  588.         else {
  589.           Write(Writeptr,diskbuffer,BUFFER);
  590.           Close(Writeptr);
  591.           if(comflag) SetComment(&Attached[0],&StringBuffer[0]);
  592.           ErrPrint("written to file ok.");
  593.  
  594.         }
  595.       }
  596. quit:
  597.    return(ret);
  598. }
  599.  
  600. Koppel(dirname,filename)
  601. char dirname[64],filename[64];
  602. {
  603.     if(dirname[0] == '\0')
  604.        { sprintf(&Attached[0],"%s",&filename[0]); return(0); };
  605.  
  606.     if((dirname[strlen(&dirname[0])-1] != ':') &&
  607.        (dirname[strlen(&dirname[0])-1] != '/'))
  608.        sprintf(&Attached[0],"%s/%s",&dirname[0],&filename[0]);
  609.     else                    /* ^ !!!! */
  610.        sprintf(&Attached[0],"%s%s",&dirname[0],&filename[0]);
  611.  
  612. return(0);
  613. }
  614.  
  615. CompWithFile()
  616. {
  617.    long ret,routret = FALSE,cntm = 0,largm = 0,larcnt = 0;
  618.    short loop;
  619.  
  620.    if(!isthereabb) { ErrPrint("No bootblock available!"); return(0); }
  621.    file[0] = '\0';
  622.  
  623.    sprintf(&kindofbb[0],"                              ");
  624.    ret = arpreq("Select file to compare with bootblock", file, readdir, FirstWindow);
  625.  
  626.     if((ret != 0) && (file[0] != '\0'))
  627.       {
  628.         Koppel(&readdir[0],&file[0]);
  629.         if((Readptr = (char *)Open(&Attached[0],READ)) == 0L) goto quit;
  630.         else {
  631.           if((Read(Readptr,Map,BUFFER)) != BUFFER)
  632.                { Close(Readptr); routret = TOSHORT; goto quit; };
  633.           Close(Readptr);
  634.         }
  635.        routret = MATCH;
  636.        for(loop=0;loop<BUFFER;loop++)
  637.         {
  638.           if(diskbuffer[loop] != Map[loop])
  639.             {
  640.               routret = NOMATCH;
  641.               if(larcnt > largm) largm = larcnt;
  642.               larcnt = 0;
  643.             }
  644.           else { cntm++; larcnt++; }
  645.         }
  646.       }
  647.     else { routret = CANCELED; goto quit; };
  648. quit:
  649. sprintf(&tmp[0],"Bytes matched: %-6ld, largest block %ld",cntm,largm);
  650. if(routret == MATCH) sprintf(&kindofbb[0],"%-25s",&file[0]);
  651. ErrPrint(&tmp[0]);
  652. Grafiek(0);
  653. return(routret);
  654. }
  655.  
  656. ReadFile()
  657. {
  658.    long ret,routret = FALSE;
  659.    short loop;
  660.  
  661.    file[0] = '\0';
  662.  
  663.    ret = arpreq("Select file to read as bootblock", file, readdir, FirstWindow);
  664.    if((ret != 0) && (file[0] != '\0'))
  665.     {
  666.         Koppel(&readdir[0],&file[0]);
  667.         if((Readptr = (char *)Open(&Attached[0],READ)) == 0L) {
  668.             sprintf(&tmp[0],"Couldn't open '%s'",&Attached[0]);
  669.             ErrPrint(&Attached[0]);
  670.             goto quit;
  671.         }
  672.        ret = Read(Readptr,Map,BUFFER);
  673.        Close(Readptr);
  674.        if((ret == -1) || (ret != BUFFER)) goto quit;
  675.        GetComment(&Attached[0]);
  676.        routret = TRUE;
  677.        for(loop=0;loop<BUFFER;loop++)
  678.         diskbuffer[loop] = Map[loop];
  679.        isthereabb = TRUE;
  680.        sprintf(&kindofbb[0],"From file: %s  ",&file[0]);
  681.        Grafiek(0);
  682.        SetColor(1,0);
  683.        PrintCurrentBB();
  684.        LayOut();
  685.     }
  686.     else { routret = CANCELED; goto quit; };
  687. quit:
  688. if(!routret) ErrPrint("Error reading file!");
  689. return(routret);
  690. }
  691.  
  692.  
  693.  
  694. Help(x,y)
  695. short x,y;
  696. {
  697. CLD();
  698. SetColor(1,0);
  699.  
  700. if((x > 545) && (x < 590) &&
  701.    (y >  30) && (y <  41))
  702.     {
  703.         Locate( 5,2); Print("Click on this gadget if you want to read");
  704.         Locate( 6,2); Print("a bootblock from the selected drive");
  705.         Locate( 7,2); Print("See Auto Comp.");
  706.         Locate( 8,2); Print("If the program fails to read a");
  707.         Locate( 9,2); Print("bootblock the previous bootblock is printed");
  708.         Locate(10,2); Print("in the third color of your WB Colors");
  709.     }
  710.  
  711. else if((x > 595) && (x < 635) &&
  712.         (y >  30) && (y <  41))  /* WRITE BOOT */
  713.     {
  714.         Locate(5,2); Print("Click on this gadget if you want to write");
  715.         Locate(6,2); Print("current bootblock to the selected drive");
  716.     }
  717.  
  718. else if((x > 595) && (x < 635) &&
  719.         (y >  60) && (y <  71)) /* WRITE FILE */
  720.     {
  721.         Locate(5,2); Print("If you select this gadget you'll be asked");
  722.         Locate(6,2); Print("for a filename. Then this program will");
  723.         Locate(7,2); Print("write the current bootblock to that file");
  724.     }
  725. else if((x > 545) && (x < 690) &&
  726.         (y >  60) && (y <  71))  /* READ FILE */
  727.     {
  728.         Locate(5,2); Print("This function reads a file as a bootblock");
  729.         Locate(6,2); Print("So you can write it to disk");
  730.     }
  731.  
  732. else if((x >  10) && (x < 530) &&
  733.         (y >  45) && (y < 180))  /* bootblock */
  734.     {
  735.         Locate(5,2); Print("This box will be used for the display");
  736.         Locate(6,2); Print("of results from several functions.");
  737.         Locate(7,2); Print("READ BOOT fe. uses it to display the ASCII");
  738.         Locate(8,2); Print("dump of the bootblock");
  739.     }
  740. else if((x >  10) && (x < 530) &&
  741.         (y >  15) && (y <  45)) /* Box around error messages */
  742.     {
  743.         Locate( 5,2); Print("That box is used to display the name and");
  744.         Locate( 6,2); Print("comment of a file that you've red with");
  745.         Locate( 7,2); Print("read-file or the name of the file that matches");
  746.         Locate( 8,2); Print("the current bootblock");
  747.         Locate(09,2); Print("Errors are printed here and the comment can be");
  748.         Locate(10,2); Print("changed (Saved only if Comment is ON)");
  749.     }
  750. else if((x > 545) && (x < 640) &&
  751.         (y > 146) && (y < 157))
  752.     {
  753.         Locate( 5,2); Print("This gadget is a gadget, that toggles");
  754.         Locate( 6,2); Print("Auto Compare. If this gadget is toggled");
  755.         Locate( 7,2); Print("to ON and you select READ BOOT,");
  756.         Locate( 8,2); Print("this program will automaticly search ");
  757.         Locate( 9,2); Print("and compare any file which is found");
  758.         Locate(10,2); Print("in a directory called BBS:. with the current");
  759.         Locate(11,2); Print("bootblock. If a file totally (1024 bytes) matches");
  760.         Locate(12,2); Print("his name will appear.");
  761.         Locate(13,2); Print("If not 'Not Identified !' will be printed on that place");
  762.         Locate(15,2); Print("The search and compare sequence can be aborted");
  763.         Locate(16,2); Print("at any time by pressing and holding");
  764.         Locate(17,2); Print("the Left button until he aborted");
  765.     }
  766. else if((x >   0) && (x < 640) &&
  767.         (y > 185) && (y < 250) && (PAL)) /* grafieken */
  768.     {
  769.         Locate( 5,2); Print("That area is used for two graphics which");
  770.         Locate( 6,2); Print("represent 1024 bytes. The lower one is always");
  771.         Locate( 7,2); Print("in the second color of your WB Colors, and");
  772.         Locate( 8,2); Print("it represents the current bootblock");
  773.         Locate( 9,2); Print("The upper represents the current file");
  774.         Locate(10,2); Print("and will be printed in the the same color as");
  775.         Locate(11,2); Print("the bootblock if that byte matches the byte");
  776.         Locate(12,2); Print("from the bootblock. if not the color is the");
  777.         Locate(13,2); Print("third color of your WB Colors (Cursor in CLI)");
  778.         Locate(14,2); Print("This can be turned off by pressing F10");
  779.     }
  780. else if((x > 535) && (x < 640) &&
  781.         (y > 134) && (y < 145))
  782.     {
  783.         Locate( 5,2); Print("When you activate the auto read option");
  784.         Locate( 6,2); Print("the program reads any bb from any disk");
  785.         Locate( 7,2); Print("that is inserted");
  786.     }
  787. else if((x > 535) && (x < 640) && (y > 111) && (y < 121))
  788.     {
  789.         Locate( 5,2); Print("Pressing this gadget gives you a do nothing");
  790.         Locate( 6,2); Print("bootblock, which can be written to disk");
  791.     }
  792. else if((x > 535) && (x < 640) && (y > 99) && (y < 109))
  793.     {
  794.         Locate( 5,2); Print("Pressing this gadget gives you a standard");
  795.         Locate( 6,2); Print("bootblock, which can be written to disk");
  796.     }
  797. else if((x > 535) && (x < 640) && (y > 122) && (y < 132))
  798.     {
  799.         Locate( 5,2); Print("If this gadget is activated the program");
  800.         Locate( 6,2); Print("writes the contents of the comment");
  801.         Locate( 7,2); Print("(string) gadget to the file if you");
  802.         Locate( 8,2); Print("select write to file");
  803.     }
  804. else if((x > 535) && (x < 640) && (y > 159) && (y < 169))
  805.     {
  806.         Locate( 5,2); Print("There is only one thing special about quit");
  807.         Locate( 6,2); Print("Since the screen of BootBase is a");
  808.         Locate( 7,2); Print("WBENCHSCREEN other programs that normally");
  809.         Locate( 8,2); Print("open their window on the WBench could open");
  810.         Locate( 9,2); Print("up on this screen, so when you quit");
  811.         Locate(10,2); Print("You'll be asked to remove those windows first");
  812.         Locate(11,2); Print("You don't have to do this but if you can");
  813.         Locate(12,2); Print("it is better to do so");
  814.         Locate(14,2); Print("Try this and you understand what I mean ");
  815.         Locate(15,2); Print("Make sure this screen is the most front screen");
  816.         Locate(16,2); Print("pull this screen down so you can click on a");
  817.         Locate(17,2); Print("WBench drawer Icon, you'll see that the drawer");
  818.         Locate(18,2); Print("window opens on BootBase' screen");
  819.     }
  820. else LayOut();
  821. return(0);
  822. }
  823.  
  824. Grafiek(which)
  825. short which;
  826. {
  827.  
  828.     short ybase;
  829.     short x,p;
  830.     short addy;
  831.  
  832.     if((!VisualComp) || (!PAL)) return(0);
  833.  
  834.     if(which == 9) goto Graph2;
  835.     ybase = 235; p = 0; x = 10; addy = 0;
  836.     SetColor(0,0); RectFill(FirstWindow->RPort,0,217,640,250);
  837.     if(which > 1) goto Graph2;
  838.  
  839.     Move(FirstWindow->RPort,0,ybase);
  840.     SetColor(2,0);
  841.     while(x < 522)
  842.       {
  843.         addy = diskbuffer[p]/10;
  844.         Draw(FirstWindow->RPort,x,ybase+addy);
  845.         addy = diskbuffer[p+1]/10;
  846.         Draw(FirstWindow->RPort,x,ybase+addy);
  847.         x++; p+=2;
  848.       }
  849.  
  850. Graph2:
  851.     SetColor(0,0); RectFill(FirstWindow->RPort,0,185,640,217);
  852.     ybase = 200; x = 10; p = 0; addy = 0;
  853.     if(which == 1) goto quit;
  854.     Move(FirstWindow->RPort,0,ybase);
  855.     while(x < 522)
  856.       {
  857.         if((diskbuffer[p] == Map[p]) || (diskbuffer[p+1] == Map[p+1]))
  858.             SetColor(2,0);
  859.         else SetColor(3,0);
  860.         addy = Map[p]/10;
  861.         Draw(FirstWindow->RPort,x,ybase+addy);
  862.         addy = Map[p+1]/10;
  863.         Draw(FirstWindow->RPort,x,ybase+addy);
  864.         x++; p+=2;
  865.       }
  866. quit:
  867. return(0);
  868. }
  869.  
  870.  
  871.  
  872. DoComparing()
  873. {
  874. struct   Lock          *disklock;
  875. struct   FileInfoBlock *fib;
  876. short flag;
  877. short loop;
  878.  
  879.    fib = 0;
  880.    disklock = 0;
  881.  
  882.    if((fib = (struct FileInfoBlock *)
  883.        AllocMem(sizeof(struct FileInfoBlock),MEMF_CLEAR)) == 0) goto quit;
  884.  
  885.    if((disklock = (struct Lock *)
  886.        Lock(&CompPath[0],SHARED_LOCK)) == 0) goto quit;
  887.  
  888.    if(!Examine(disklock,fib)) goto quit;
  889.    if(fib->fib_DirEntryType < 0) goto quit;
  890.  
  891.    Grafiek(1);
  892.    while(ExNext(disklock, fib))
  893.     {
  894.         if(fib->fib_DirEntryType > 0) goto next;
  895.         Koppel(&CompPath[0],fib->fib_FileName);
  896.         if((Readptr = (char *)Open(&Attached[0],READ)) == 0L) goto quit;
  897.         else if((Read(Readptr,Map,BUFFER)) != BUFFER)
  898.                 { Close(Readptr); goto next; };
  899.         Close(Readptr);
  900.         sprintf(&tmp[0],"Comparing with %s",fib->fib_FileName);
  901.         ErrPrint(&tmp[0]);
  902.         flag = TRUE;
  903.         for(loop=0;loop<BUFFER;loop++)
  904.           if(diskbuffer[loop] != Map[loop])
  905.             { flag = FALSE; break; };
  906.         Grafiek(9);
  907.         if(flag)
  908.           {
  909.             sprintf(&kindofbb[0],"%-25s",fib->fib_FileName);
  910.             goto quit;
  911.           }
  912.         if(((*LeftMouse & 0x40) != 0x40) &&
  913.            (IntuitionBase->ActiveWindow == FirstWindow)) goto quit;
  914. next:
  915.     }
  916.    sprintf(&kindofbb[0],"Not identified !         ");
  917. quit:
  918.    if(flag) GetComment(&Attached[0]);
  919.    if (disklock) UnLock(disklock);
  920.    if(fib)       FreeMem(fib,sizeof(fib));
  921.    LayOut();
  922. return(0);
  923. }
  924.  
  925.  
  926. WriteBootBlock()
  927. {
  928. short writeerr;
  929. char oneline[100];
  930.  
  931.    if(!isthereabb)
  932.      { ErrPrint("No bootblock available!"); return(FALSE); };
  933.    if((diskport = CreatePort(0,0)) == 0)
  934.      { ErrPrint(NOPORT); return(FALSE); };
  935.  
  936.    if((diskreq = (struct IOExtTD *)
  937.              CreateExtIO(diskport,sizeof(struct IOExtTD))) == NULL)
  938.                   { DeletePort(diskport); ErrPrint(NOEXT); return(FALSE); }
  939.  
  940.    if(OpenDevice(TD_NAME,drive,diskreq,0))
  941.      {
  942.        DeleteExtIO(diskreq,sizeof(struct IOExtID));
  943.        DeletePort(diskport);
  944.        ErrPrint(NODISK);
  945.      }
  946.  
  947.    diskreq->iotd_Req.io_Command = TD_CHANGESTATE;
  948.    DoIO(diskreq);
  949.    if(diskreq->iotd_Req.io_Actual != 0)
  950.     {
  951.        CloseDevice(diskreq);
  952.        DeleteExtIO(diskreq,sizeof(struct IOExtTD));
  953.        DeletePort(diskport);
  954.        ErrPrint(NODISK);
  955.        return(FALSE);
  956.     }
  957.    diskreq->iotd_Req.io_Command = TD_PROTSTATUS;
  958.    DoIO(diskreq);
  959.    if(diskreq->iotd_Req.io_Actual != 0)
  960.     {
  961.        CloseDevice(diskreq);
  962.        DeleteExtIO(diskreq,sizeof(struct IOExtTD));
  963.        DeletePort(diskport);
  964.        ErrPrint(PROTECT);
  965.        return(FALSE);
  966.     }
  967.  
  968.    diskreq->iotd_Req.io_Command = TD_CHANGENUM;
  969.    DoIO(diskreq);
  970.    diskchangecount = diskreq->iotd_Req.io_Actual;
  971.  
  972.    MotorOn();
  973.    writeerr = WriteCylSec(0,0,0);
  974.    MotorOff();
  975.    if(writeerr > 19)
  976.       {
  977.         CLD();
  978.         sprintf(&oneline[0],"Write Error: %-7d",writeerr);
  979.         Print(&oneline[0]);
  980.         SetColor(3,0);
  981.         if(isthereabb) PrintCurrentBB();
  982.       }
  983.    else
  984.       {
  985.         CLD();
  986.         ErrPrint("Written to disk Ok.     ");
  987.         SetColor(1,0);
  988.         PrintCurrentBB();
  989.         Grafiek(1);
  990.         StringBuffer[0] = '\0'; UndoBuffer[0] = '\0';
  991.         RefreshGadgets(&StringGadget,FirstWindow,NULL);
  992.       }
  993.    CloseDevice(diskreq);
  994.    DeleteExtIO(diskreq,sizeof(struct IOExtTD));
  995.    DeletePort(diskport);
  996. return(NOPROB);
  997. }
  998.  
  999. WriteCylSec(cyl,sec,hd)
  1000. SHORT cyl,sec,hd;
  1001. {
  1002.    LONG offset;
  1003.  
  1004.    diskreq->iotd_Req.io_Length = BUFFER;
  1005.    diskreq->iotd_Req.io_Data   = (APTR)diskbuffer;
  1006.    diskreq->iotd_Req.io_Command = ETD_WRITE;
  1007.    diskreq->iotd_Count = diskchangecount;
  1008.    offset = TD_SECTOR * (sec + NUMSECS * hd + NUMSECS * NUMHEADS * cyl);
  1009.    diskreq->iotd_Req.io_Offset = offset;
  1010.    DoIO(diskreq);
  1011.    diskreq->iotd_Req.io_Command = CMD_UPDATE;
  1012.    DoIO(diskreq);
  1013. return(diskreq->iotd_Req.io_Error);
  1014. }
  1015.  
  1016.  
  1017. MakeNobootbuf()
  1018. {
  1019.     short loop;
  1020.  
  1021.     for(loop=0;loop<1024;loop += 4)
  1022.       {
  1023.         diskbuffer[loop]   = 'D';
  1024.         diskbuffer[loop+1] = 'O';
  1025.         diskbuffer[loop+2] = 'S';
  1026.         diskbuffer[loop+3] = 0x00;
  1027.       }
  1028.     sprintf(&kindofbb[0],"Do nothing bootblock     ");
  1029.     isthereabb = TRUE;
  1030.     LayOut();
  1031. return(0);
  1032. }
  1033.  
  1034. MakeStanbuf()
  1035. {
  1036.     short loop;
  1037.  
  1038.     sprintf(&kindofbb[0],"Standard 1.2/1.3         ");
  1039.     for(loop=0;loop<1024;loop++)
  1040.       {
  1041.         if(loop < 49) diskbuffer[loop] = standard[loop];
  1042.         else          diskbuffer[loop] = 0x00;
  1043.       }
  1044.     isthereabb = TRUE;
  1045.     LayOut();
  1046. return(0);
  1047. }
  1048.  
  1049.  
  1050. CheckIfStandard()
  1051. {
  1052. short loop,chk = TRUE;
  1053.  
  1054.     for(loop=0;loop<1024;loop++)
  1055.       {
  1056.         if((loop < 49) && (diskbuffer[loop] != standard[loop])) chk = FALSE;
  1057.         else if((loop >= 49) && (diskbuffer[loop] != 0x00))     chk = FALSE;
  1058.       }
  1059.     if(chk == TRUE) return(1);
  1060.  
  1061.     chk = TRUE;
  1062.     for(loop=0;loop<1024;loop += 4)
  1063.       {
  1064.         if((diskbuffer[loop]   != 'D') ||
  1065.            (diskbuffer[loop+1] != 'O') ||
  1066.            (diskbuffer[loop+2] != 'S')) { chk = FALSE; break; };
  1067.         /* There is no test for diskbuffer[loop+3] because I've seen
  1068.            a lot of different versions and it doesn't really matter
  1069.            what's at this location, it can't be a virus or an executable */
  1070.  
  1071.       }
  1072.     if(chk == TRUE) return(2);
  1073.     return(0);
  1074. }
  1075.  
  1076. AreYouSure(txtno,txtlen,col)
  1077. short txtno,txtlen,col;
  1078. {
  1079. short x,y,start;
  1080. long ret = FALSE;
  1081. long ledge,tedge,maxy = 256;
  1082.     if(!PAL) maxy = 200;
  1083.     ledge = FirstWindow->MouseX-265;
  1084.     tedge = FirstWindow->MouseY-50;
  1085.     if(ledge < 0) ledge = 0;
  1086.     if(ledge > 335) ledge = 335;
  1087.     if(tedge < 0) tedge = 0;
  1088.     if(tedge > maxy-100) tedge = maxy-100;
  1089.     ReqWindow.LeftEdge = ledge;
  1090.     ReqWindow.TopEdge  = tedge;
  1091.     if(!(reqwin = (struct Window *)OpenWindow(&ReqWindow))) return(FALSE);
  1092.  
  1093.     if(txtlen > 6) txtlen = 6;
  1094.     SetColor(col,0);
  1095.     x = 10;
  1096.     start = 20+(((6-txtlen)/2)*8);
  1097.     for(y=txtno;y<(txtno+txtlen);y++)
  1098.       {
  1099.         Move(reqwin->RPort,x,start+((y-txtno)*8));
  1100.         Text(reqwin->RPort,ReqTexts[y],strlen(ReqTexts[y]));
  1101.       }
  1102.  
  1103.     for(;;)
  1104.      {
  1105.       if ((message = (struct IntuiMessage *)
  1106.           GetMsg(reqwin->UserPort)) == NULL)
  1107.             {
  1108.                 Wait(1<<reqwin->UserPort->mp_SigBit);
  1109.                 continue;
  1110.             }
  1111.       MessageClass = message->Class;
  1112.       code      = message->Code;
  1113.       GadgetPtr = (struct Gadget *) message->IAddress;
  1114.       GadgetID  = GadgetPtr->GadgetID;
  1115.       ReplyMsg(message);
  1116.  
  1117.  
  1118.       switch (MessageClass)
  1119.          {
  1120.          case GADGETUP      :
  1121.                               if(GadgetID == 1) { ret = (TRUE); goto quit; }
  1122.                               else if(GadgetID == 2) { ret = FALSE; goto quit; }
  1123.                               break;
  1124.  
  1125.          }
  1126.      }
  1127. quit:
  1128.     if(reqwin) CloseWindow(reqwin);
  1129.     return(ret);
  1130. }
  1131.  
  1132.  
  1133.  
  1134. DiskIns()
  1135. {
  1136.     short lus,cd = FALSE;
  1137.  
  1138.     if((diskport = CreatePort(0,0)) == 0) return(NOPORT);
  1139.     if((diskreq = (struct IOExtTD *)
  1140.       CreateExtIO(diskport,sizeof(struct IOExtTD))) == NULL)
  1141.         { DeletePort(diskport); return(NOEXT);};
  1142.  
  1143.     for(lus = 0;lus < 4;lus++)
  1144.         {
  1145.             if(!availdrives[lus]) continue;
  1146.             OpenDevice(TD_NAME,lus,diskreq,0);
  1147.  
  1148.             diskreq->iotd_Req.io_Command = TD_CHANGESTATE;
  1149.             DoIO(diskreq);
  1150.  
  1151.             if(diskreq->iotd_Req.io_Actual != 0)
  1152.               { CloseDevice(diskreq); continue; }
  1153.  
  1154.             diskreq->iotd_Req.io_Command = TD_CHANGENUM;
  1155.             DoIO(diskreq);
  1156.             diskchangecount = diskreq->iotd_Req.io_Actual;
  1157.             CloseDevice(diskreq);
  1158.             if(!setupcnt)
  1159.               {
  1160.               if(remcount[lus] != diskchangecount)
  1161.                 {
  1162.                   if(AutoRead)
  1163.                       {  GadgetID = 14 - lus; DriveSelect(); };
  1164.                   cd = TRUE;
  1165.                   remcount[lus] = diskchangecount;
  1166.                   goto quit;
  1167.                 }
  1168.               }
  1169.             else remcount[lus] = diskchangecount;
  1170.         }
  1171. quit:
  1172.    DeleteExtIO(diskreq,sizeof(struct IOExtTD));
  1173.    DeletePort(diskport);
  1174.    if(cd) return(0);
  1175.    return(TRUE);
  1176. }
  1177.  
  1178.  
  1179. GetComment(whichfile)
  1180. char whichfile[200];
  1181. {
  1182. struct   Lock          *disklock;
  1183. struct   FileInfoBlock *fib;
  1184.  
  1185.    short ret = 0;
  1186.    fib = 0;
  1187.    disklock = 0;
  1188.  
  1189.    if((fib = (struct FileInfoBlock *)
  1190.        AllocMem(sizeof(struct FileInfoBlock),MEMF_CLEAR)) == 0) goto quit;
  1191.  
  1192.    if((disklock = (struct Lock *)
  1193.        Lock(&whichfile[0],SHARED_LOCK)) == 0) goto quit;
  1194.  
  1195.    if(!Examine(disklock,fib)) goto quit;
  1196.    sprintf(&StringBuffer[0],"%s",fib->fib_Comment);
  1197.    RefreshGadgets(&StringGadget,FirstWindow,NULL);
  1198.    ret = 1;
  1199.  
  1200. quit:
  1201.    if (disklock) UnLock(disklock);
  1202.    if(fib)       FreeMem(fib,sizeof(fib));
  1203. return(ret);
  1204. }
  1205.  
  1206. PrintKeys()
  1207. {
  1208. CLD();
  1209.  
  1210.     Locate(5,10); Print("Available keys (RAWKEY)");
  1211.     Locate(6,2);  Print("F1   =  Compare with file; Sorry no gadget!");
  1212.     Locate(7,2);  Print("F9   =  Redraw");
  1213.     Locate(8,2);
  1214.     if(PAL)     { Print("F10  =  toggle graphics"); Locate(9,2); }
  1215.                   Print("ESC  =  Quit");
  1216. return(0);
  1217. }
  1218.  
  1219. Do_RawKey(key)  /* Perform actions on certain keys */
  1220. USHORT key;
  1221. {
  1222.     switch(key)
  1223.         {
  1224.             case F1     : CompWithFile();
  1225.                           break;
  1226.             case F9     : RefreshGadgets(&ReadBB,FirstWindow,NULL);
  1227.                           LayOut(); Grafiek(0); break;
  1228.             case F10    :
  1229.                           if(PAL)
  1230.                             {
  1231.                               if(VisualComp) {
  1232.                                    VisualComp = FALSE;
  1233.                                    SetColor(0,0);
  1234.                                    RectFill(FirstWindow->RPort,0,180,640,250);
  1235.                                    SetColor(1,0);
  1236.                               }
  1237.                               else { VisualComp = TRUE; Grafiek(0); }
  1238.                             }
  1239.                           break;
  1240.             case ESC    : if(AreYouSure(3,1,3)) Close_All(); break;
  1241.             case HELP   : PrintKeys();
  1242.                           break;
  1243.         }
  1244.     return(0);
  1245. }
  1246.  
  1247.  
  1248.